package com.expand.demo.expandable;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;

import com.expand.demo.R;
import com.expand.demo.expandable.utils.Constant;
import com.expand.demo.expandable.widget.TitleView;
import com.rich.widget.ExpandableTextView;
import com.rich.widget.MoreLineTextView;
import com.rich.widget.utils.DensityUtil;


/**
 * Expandable
 * mTvExpandableShort
 *
 * @Description TextView多文本折叠/展开效果
 * @Author 一花一世界
 */
public class ExpandableActivity extends AppCompatActivity {

    public static void jumpTo(Context context) {
        Intent intent = new Intent(context, ExpandableActivity.class);
        context.startActivity(intent);
    }

    private TitleView titleView;
    private MoreLineTextView mTvMoreLineShort;
    private ExpandableTextView mTvExpandableShort;
    private MoreLineTextView mTvMoreLineLong;
    private ExpandableTextView mTvExpandableLong;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        DensityUtil.init(this);
        setContentView(R.layout.activity_expand_able);
        initView();
        initData();
    }

    private void initView() {
        titleView = (TitleView) findViewById(R.id.titleView);
        titleView.setAppTitle(getString(com.rich.widget.R.string.title));
        titleView.setLeftImageVisibility(View.GONE);
        mTvMoreLineShort = (MoreLineTextView) findViewById(R.id.tv_more_line_short);
        mTvExpandableShort = (ExpandableTextView) findViewById(R.id.tv_expandable_short);
        mTvMoreLineLong = (MoreLineTextView) findViewById(R.id.tv_more_line_long);
        mTvExpandableLong = (ExpandableTextView) findViewById(R.id.tv_expandable_long);
    }

    private void initData() {
        mTvMoreLineShort.setText(Constant.content1);
        mTvExpandableShort.setText(Constant.content2);
        mTvMoreLineLong.setText(Constant.content3);
        //mTvExpandableLong.setText(Constant.content4);

        String text = Constant.content4;
        SpannableString spannableString = new SpannableString(text);
        spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#FFEB78")), 1, 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#E51C23")), 10, 20, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        //tvDescription.setText(spannableString);
        mTvExpandableLong.setText(spannableString);
    }

}
